import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import SockJS from 'sockjs-client'
import path from 'node:path'

// https://vitejs.dev/config/
export default defineConfig({
  
  plugins: [
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    // SockJS(),
    vue()],
    server :{
      proxy:{
        '/api':{
          target:"http://localhost:8080",
          changeOrigin:true,
          rewrite:(path)=>path.replace(/^\/api/,'')
        },
        '/websocket':{
          target:"ws://localhost:8080/websocket",
          changeOrigin:true,
          rewrite:(path)=>path.replace(/^\/websocket/,'')
        }
      }
    },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  devServer: {
    headers: {
      'Access-Control-Allow-Origin': '*',
    }
  },
  transpileDependencies: true,
  css:{
    preprocessorOptions: {
      scss: {
        additionalData: `@use "~/styles/element/index.scss" as *;`,
      },
    },
  }
})
